﻿/*----------------------------------------------------------------
// Copyright (C) 2009 
// 版权所有。 
//
// 文件名：
// 文件功能描述：设备保管信息查询
//
//
// 创建标识：
// 程序作者：翟允锋
// 修改标识：
// 修改描述：
//----------------------------------------------------------------*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using EQT.Dal;
using System.Threading;
using EQT.Model;
using Wuqi.Webdiyer;

public partial class EquipKeptQuery : System.Web.UI.Page
{
    private static readonly Common.Logging.ILog log = Common.Logging.LogManager.GetCurrentClassLogger();
    private DaKeptLog dalKept = DevFuture.Common.WorkContext.AppCtx.GetObject("DaKeptLog") as DaKeptLog;
    private UserContext context;

    protected void Page_Load(object sender, EventArgs e)
    {
        context = Session["USER_CONTEXT"] as UserContext;
        OperationResult.Text = "";
        divResult.Visible = false;
        AspNetPager.PageSize = 15;

        if(!IsPostBack)
        {
            this.BtnQuery_Click(null, null);
        }
    }

    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        this.BtnQuery_Click(null, null);
    }

    protected void BtnQuery_Click(object sender, EventArgs e)
    {
        int pagecount = 0;
        string strCondition = "where 1=1 ";
        if (sender != null && e != null)
        {
            AspNetPager.CurrentPageIndex = 0;
        }

        if (!string.IsNullOrEmpty(TxtEquipID.Text.Trim()))
        {
            strCondition = strCondition + "and  Equip_ID='" + TxtEquipID.Text.Trim() + "'";
        }
        
        this.GridView.DataSource = dalKept.GetEquipKeptRecords(strCondition, AspNetPager.PageSize, AspNetPager.CurrentPageIndex - 1, out pagecount);
        this.GridView.DataBind();

        AspNetPager.RecordCount = pagecount;

    }

    protected void GvDetail_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        GridViewRow gvr = (GridViewRow)btn.NamingContainer;
        string strKey = ((GridView)gvr.NamingContainer).DataKeys[gvr.RowIndex].Value.ToString();

        if (string.IsNullOrEmpty(strKey))
        {
            return;
        }
        DataSet ds = dalKept.GetEquipKeptRecords(" where Kpt_Log_ID='" + strKey + "'");

        labEquip_ID.Text = ds.Tables[0].Rows[0]["Equip_ID"].ToString();
        labStatusName.Text = ds.Tables[0].Rows[0]["StatusName"].ToString();
        labEquip_Name.Text = ds.Tables[0].Rows[0]["Equip_Name"].ToString();
        labKpt_Addr.Text = ds.Tables[0].Rows[0]["Kpt_Addr"].ToString();
        labKpt_Begin.Text = ds.Tables[0].Rows[0]["Kpt_Begin"].ToString();
        labKpt_End.Text = ds.Tables[0].Rows[0]["Kpt_End"].ToString();
        labRem.Text = ds.Tables[0].Rows[0]["Rem"].ToString();
        labUser_Code1.Text = ds.Tables[0].Rows[0]["FullName1"].ToString();
        labUser_Code2.Text = ds.Tables[0].Rows[0]["FullName2"].ToString();
        this.SetPanelVisiable(DetailPanel);
    }

    protected void BtnExport_Click(object sender, EventArgs e)
    {
        string strCondition = "where 1=1 ";

        if (!string.IsNullOrEmpty(TxtEquipID.Text.Trim()))
        {
            strCondition = strCondition + "and  Equip_ID='" + TxtEquipID.Text.Trim() + "'";
        }

        DataSet ds = dalKept.GetEquipKeptRecords(strCondition);

        GridViewExport.DataSource = ds;
        GridViewExport.DataBind();

        GridViewExportUtil.Export("KeptRecords.xls", GridViewExport);
        GridViewExport.DataSource = null;
        GridViewExport.DataBind();
    }

    protected void DetailBack_Click(object sender, EventArgs e)
    {
        labEquip_ID.Text = "";
        labKpt_Addr.Text = "";
        labKpt_Begin.Text = "";
        labKpt_End.Text = "";
        labRem.Text = "";
        labUser_Code1.Text = "";
        labUser_Code2.Text = "";
        labEquip_Name.Text = "";
        labStatusName.Text = "";
        this.SetPanelVisiable(SummaryPanel);
    }

    protected void SetPanelVisiable(Panel panel)
    {
        DetailPanel.Visible = false;
        SummaryPanel.Visible = false;

        panel.Visible = true;
    }
}
